package com.iweipan.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.iweipan.R;
import com.iweipan.adapter.HomeFragmentAdapter;
import com.iweipan.base.WPBaseActivity;
import com.iweipan.fragment.FourFragment;
import com.iweipan.fragment.InforMationFragment;
import com.iweipan.fragment.ThreeFragment;
import com.iweipan.fragment.TwoFragment;
import com.iweipan.view.TheHomeViewPager;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/11/17.
 */

public class WPHomeActivity extends WPBaseActivity implements InforMationFragment.RefreshMoney{
    @BindView(R.id.vp_home)
    TheHomeViewPager vpHome;
    @BindView(R.id.bottom_navigation_bar)
    BottomNavigationBar bottomNavigationBar;
    private ArrayList<Fragment> fragments = new ArrayList<>();

    private HomeFragmentAdapter homeFragmentAdapter;
    private FourFragment fourFragment;
    private TwoFragment twoFragment;
    private ThreeFragment threeFragment;
    private String go_to;

    @Override
    public int bindLayout() {
        return R.layout.activity_home;
    }

    @Override
    public void initToolbarColor() {
        color = getResources().getColor(R.color.actionbar_title_bg);
        statusBarAlpha = 60;
    }

    @Override
    public void initView(View view) {
//        XGPushConfig.enableDebug(this, true);


        bottomNavigationBar
                .addItem(new BottomNavigationItem(R.mipmap.shouye_icon_01, "首页").setActiveColorResource(R.color.colorAccent))
                .addItem(new BottomNavigationItem(R.mipmap.hemai_icon_01, "交易明细").setActiveColorResource(R.color.colorPrimary))
                .addItem(new BottomNavigationItem(R.mipmap.yaoqing_icon_01, "出入明细").setActiveColorResource(R.color.colorPrimaryDark))
                .addItem(new BottomNavigationItem(R.mipmap.geren_icon_01, "个人中心").setActiveColorResource(R.color.holo_red))
                .setMode(BottomNavigationBar.MODE_FIXED)
                .setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC)
                .setFirstSelectedPosition(0)
                .initialise();
        fourFragment = FourFragment.newInstance();
        twoFragment = TwoFragment.newInstance();
        threeFragment = ThreeFragment.newInstance();
        fragments.add(InforMationFragment.newInstance());
        fragments.add(twoFragment);
        fragments.add(threeFragment);
        fragments.add(fourFragment);

        homeFragmentAdapter = new HomeFragmentAdapter(getSupportFragmentManager(), fragments);
        vpHome.setOffscreenPageLimit(4);
        vpHome.setAdapter(homeFragmentAdapter);

        vpHome.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                bottomNavigationBar.selectTab(position);


            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        bottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
            @Override
            public void onTabSelected(int position) {
                vpHome.setCurrentItem(position);
            }

            @Override
            public void onTabUnselected(int position) {

            }

            @Override
            public void onTabReselected(int position) {

            }
        });
    }

    @Override
    public void doBusiness(Context mContext) {
        Intent intent = getIntent();
         go_to = intent.getStringExtra("go_to");
        if (go_to != null) {
            if (go_to.equals("two")) {
                vpHome.setCurrentItem(1);
                twoFragment.setGoToTwo();
//                new Handler(new Handler.Callback() {
//                    @Override
//                    public boolean handleMessage(Message msg) {
//
//                        return false;
//                    }
//                }).sendEmptyMessageDelayed(0,2000);

            }
        }


    }

    @Override
    public void resume() {

    }

    @Override
    public void destroy() {

    }


    @Override
    public void clean() {
        fourFragment.reFresh();
    }


}
